<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:ns='http://xml.netbeans.org/schema/userschema_old' xmlns:ns1='http://xml.netbeans.org/schema/orderuser_old'  xmlns:ns2='http://xml.netbeans.org/schema/orderdetail_old'
exclude-result-prefixes="ns,n1,n2"
>
    <xsl:variable name="order" select="document('../XML/Orderxml.xml')"/>
    <xsl:variable name="orderdetail" select="document('../XML/Orderdetailxml.xml')"/>
    <xsl:variable name="tong" />
    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="first"
                margin-right='1in'
                margin-left='0.5in'
                margin-bottom='0.5in'
                margin-top='0.5in'
                page-width='9in'
                page-height='11in'>
                    <fo:region-body margin-top='0.5in'/>
                        <fo:region-before extent='1in'/>
                        <fo:region-after extent='0.75in'/>
                        </fo:simple-page-master>
                        </fo:layout-master-set>
            <fo:page-sequence master-reference='first'>
                <fo:static-content flow-name='xsl-region-before'>
                    <fo:block line-height='14pt' font-size='20pt' text-align='center'>Order Detail</fo:block>
                </fo:static-content>
                <fo:static-content flow-name='xsl-region-after'>
                       <fo:block line-height='14pt' font-size='10pt'
                       text-align='end'>Ho Chi Minh,<xsl:call-template name="formatdate">
                                    <xsl:with-param name="datestr" select="$order//ns1:OrderDate"/>
                                </xsl:call-template>
                        </fo:block>
                        <fo:block line-height='14pt' font-size='10pt' text-align='end'>Page<fo:page-number/></fo:block>
                </fo:static-content>
                <fo:flow flow-name="xsl-region-body">
                    <fo:block>

                        <fo:table margin-left='0.5in' >
                         <fo:table-column column-width='10cm'/>
                        <fo:table-column column-width='7cm'/>
                        <fo:table-body>
                      <fo:table-row>
                        <fo:table-cell>
                        <fo:block line-height='200%'>
                        FullName: <xsl:value-of select="//ns:FullName"/> </fo:block>
                        </fo:table-cell>
                        <fo:table-cell number-rows-spanned='4'>
                        <fo:block text-align='right' line-height='200%'>
                        <fo:external-graphic src='C:\Users\annt60258\Documents\NetBeansProjects\banmaytinh\web\newimages\logo.jpg'  height='2.00in'  content-width='2.00in'  />
                        </fo:block>
                        </fo:table-cell>
                        </fo:table-row>
                        <fo:table-row>
                        <fo:table-cell> <fo:block line-height='200%'>
                        Email: <xsl:value-of select="//ns:Email"/> </fo:block>
                        </fo:table-cell>
                        </fo:table-row> <fo:table-row>
                        <fo:table-cell> <fo:block line-height='200%'>  Phone: <xsl:value-of select="//ns:Phone"/> </fo:block>
                        </fo:table-cell> </fo:table-row> <fo:table-row>
                        <fo:table-cell><fo:block line-height='200%'>Address: <xsl:value-of select="//ns:Address"/> </fo:block> </fo:table-cell>
                        </fo:table-row>
                        </fo:table-body>
                        </fo:table>
                        <fo:table border='solid black' >
                        <fo:table-column column-width='2cm'/>
                        <fo:table-column column-width='8cm'/>
                        <fo:table-column column-width='2cm'/>
                        <fo:table-column column-width='4cm'/>
                        <fo:table-column column-width='4cm'/>
                        <fo:table-header >
                        <fo:table-row>
                        <fo:table-cell border-style='solid'>
                        <fo:block line-height='200%' font-weight='bold' text-align='center' border-style='solid' border-width='1pt' border-color='black' background-color='#F7F24D'>
                        Image
                        </fo:block>
                        </fo:table-cell>
                        <fo:table-cell border-style='solid'>
                        <fo:block line-height='200%' font-weight='bold' text-align='center' border-style='solid' border-width='1pt' border-color='black' background-color='#F7F24D'>
                        Product
                        </fo:block>
                        </fo:table-cell>
                        <fo:table-cell border-style='solid'>
                        <fo:block line-height='200%' font-weight='bold' text-align='center' border-style='solid'  border-width='1pt' border-color='black' background-color='#F7F24D'>
                        Number
                        </fo:block>
                        </fo:table-cell>
                        <fo:table-cell border-style='solid'>
                        <fo:block line-height='200%' font-weight='bold' text-align='center' border-style='solid'  border-width='1pt' border-color='black' background-color='#F7F24D'>
                            Price
                            </fo:block>
                            </fo:table-cell>
                            <fo:table-cell border-style='solid'>
                        <fo:block line-height='200%' font-weight='bold' text-align='center' border-style='solid'  border-width='1pt' border-color='black' background-color='#F7F24D'>
                            Money
                            </fo:block>
                            </fo:table-cell>
                            </fo:table-row>
                            </fo:table-header>
                            <fo:table-body >
                                <xsl:for-each select="$orderdetail/ns2:Orderdetails/ns2:Orderdetail">
                            <fo:table-row>
                            <fo:table-cell border-style='solid'>
                            <fo:block border-right-width='0.5pt' text-align='center'  >
                            <fo:external-graphic>
                            <xsl:attribute name="src">
                                <xsl:value-of select="ns2:Picture"/>
                            </xsl:attribute>
                            
                            <xsl:attribute name='content-width'>
                                2.00in
                            </xsl:attribute>
                            <xsl:attribute name='height'>
                                1.00in
                            </xsl:attribute>

                            
                            </fo:external-graphic>
                            </fo:block>
                            </fo:table-cell>
                            <fo:table-cell border-style='solid'>
                            <fo:block border-right-width='0.5pt' line-height='250%'  text-align='center'  >
                             <xsl:value-of select="ns2:ProductName"/> </fo:block>
                            </fo:table-cell>
                            <fo:table-cell border-style='solid'>
                            <fo:block border-right-width='0.5pt' line-height='736%' text-align='center'  >
                            <xsl:value-of select="ns2:Quantity"/>
                            </fo:block>
                            </fo:table-cell>
                            <fo:table-cell border-style='solid'>
                            <fo:block  line-height='736%' text-align='center'  >
                             <xsl:value-of select="format-number(ns2:Price,'###,###')"/>VND
                            </fo:block>
                            </fo:table-cell>
                            <fo:table-cell border-style='solid'>
                            <fo:block  line-height='736%' text-align='center'   >
                             <xsl:value-of select="format-number(ns2:Price*ns2:Quantity,'###,###')"/>VND
                            </fo:block>
                            </fo:table-cell>
                            </fo:table-row>
                            </xsl:for-each>
               <fo:table-row>
                   
                   <fo:table-cell number-columns-spanned='3' ><fo:block  line-height='200%' text-align='center'>Total</fo:block></fo:table-cell>
                   
                   <fo:table-cell number-columns-spanned='2' border-style='solid'>
                       <fo:block color='red'  line-height='200%' text-align='center'><xsl:value-of select="format-number($orderdetail//ns2:Tong,'###,###,###')"/>VND</fo:block>
                       </fo:table-cell>
               </fo:table-row>
                </fo:table-body>
                </fo:table>
                </fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
    <xsl:template name="formatdate">
        <xsl:param name="datestr" />
     <!-- input format mmddyyyy -->
     <!-- output format mm/dd/yyyy -->

        <xsl:variable name="mm">
            <xsl:value-of select="substring($datestr,6,2)" />
        </xsl:variable>

        <xsl:variable name="dd">
            <xsl:value-of select="substring($datestr,9,2)" />
        </xsl:variable>

        <xsl:variable name="yyyy">
            <xsl:value-of select="substring($datestr,1,4)" />
        </xsl:variable>

         <xsl:variable name="hh">
            <xsl:value-of select="substring($datestr,12,2)" />
        </xsl:variable>

        <xsl:variable name="mimi">
            <xsl:value-of select="substring($datestr,15,2)" />
        </xsl:variable>

        <xsl:variable name="ss">
            <xsl:value-of select="substring($datestr,18,2)" />
        </xsl:variable>

        <xsl:value-of select="$yyyy" />
        <xsl:value-of select="'-'" />
        <xsl:value-of select="$mm" />
        <xsl:value-of select="'-'" />
        <xsl:value-of select="$dd" />
        <xsl:value-of select="' '" />
        <xsl:value-of select="$hh" />
        <xsl:value-of select="':'" />
        <xsl:value-of select="$mimi" />
        <xsl:value-of select="':'" />
        <xsl:value-of select="$ss" />

    </xsl:template>
</xsl:stylesheet>
